package wang.hex.codetransfer.code.gui;

import java.awt.*;

import javax.swing.*;


public class ImagePanel extends JPanel {


    private Image img;

    public ImagePanel(Image img) {             //构造
        this.img = img;
    }


    public void paintComponent(Graphics g) {
        if (img != null) {
            g.drawImage(img, 0, 0, null);
        }
    }

    public void changeImage(Image img) {
        this.img = img;
        Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
        setSize(size);
        setPreferredSize(size);
        setMinimumSize(size);
        setMaximumSize(size);
        setLayout(null);
        getGraphics().drawImage(img, 0, 0, null);
    }


}